load("@fmeum_rules_jni//jni:defs.bzl", "cc_jni_library")

cc_jni_library(
    name = "native_asan",
    srcs = [
        "com_example_ExampleFuzzerWithNative.cpp",
    ],
    copts = [
        "-fsanitize=fuzzer-no-link,address",
        "-fno-sanitize-blacklist",
    ],
    linkopts = select({
        "//:clang_on_linux": ["-fuse-ld=lld"],
        "@platforms//os:windows": [
            # Windows requires all symbols that should be imported from the main
            # executable to be defined by an import lib.
            "/wholearchive:clang_rt.asan_dll_thunk-x86_64.lib",
        ],
        "//conditions:default": [],
    }),
    visibility = ["//examples:__pkg__"],
    deps = [
        "//examples:example_fuzzer_with_native_lib.hdrs",
    ],
)

cc_jni_library(
    name = "native_ubsan",
    srcs = [
        "com_example_ExampleFuzzerWithNative.cpp",
    ],
    copts = [
        "-fsanitize=fuzzer-no-link,undefined",
        "-fno-sanitize-recover=all",
    ],
    linkopts = select({
        "//:clang_on_linux": ["-fuse-ld=lld"],
        "@platforms//os:windows": [
            # Using the asan thunk is correct here as it contains symbols for
            # UBSan and SanCov as well.
            "/wholearchive:clang_rt.asan_dll_thunk-x86_64.lib",
        ],
        "//conditions:default": [],
    }),
    visibility = ["//examples:__pkg__"],
    deps = [
        "//examples:example_fuzzer_with_native_lib.hdrs",
    ],
)
